<?php

namespace app\admin\model;

use app\common\library\Log;
use think\Model;
use traits\model\SoftDelete;

class Shops extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'shops';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'country_id',
        'country_id_text'
    ];

    public function getCountryIdTextAttr($value, $data)
    {
        $countryModel = new Country();
        $status = $countryModel->getCountryList();
        return $status[$data['country_id']];
    }
    public function shopsByIdIndexList()
    {
        $shops = $this->field('id,name')->select();
        $list = [];
        foreach ($shops as $item){
            $list[$item['id']] = $item['name'];
        }
        return $list;
    }
    
    public function country()
    {
        return $this->belongsTo('Country', 'country_id')->setEagerlyType(0);
    }

    public static function shopsByIdIndexListStatic()
    {
        $shops = self::field('id,name')->select();
        $list = [];
        foreach ($shops as $item){
            $list[$item['id']] = $item['name'];
        }
        return $list;
    }





}
